package vn.com.demand.lux.view.labelprovider;

import java.util.List;

import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

import vn.com.demand.lux.model.AccountReceivableDetailBean;
import vn.com.demand.util.DpUtils;

public class InterestCaculationLabelProvider implements ITableLabelProvider,IColorProvider {
	
	private Color odd = new Color(Display.getCurrent(), 236, 251, 249);
	private Color event = new Color(Display.getCurrent(), 248, 248, 248);
	private List<AccountReceivableDetailBean> list;
	
	public List<AccountReceivableDetailBean> getList() {
		return list;
	}

	public void setList(List<AccountReceivableDetailBean> list) {
		this.list = list;
	}

	public Image getColumnImage(Object element, int columnIndex) {
		return null;
	}

	public String getColumnText(Object element, int columnIndex) {
		AccountReceivableDetailBean rs = (AccountReceivableDetailBean) element;
		String format = "###,###,###,###.00";
		String formatVND = "###,###,###,###,###";
		double value = 0;
		switch (columnIndex) {
		case 0:
			return DpUtils.format(rs.getDate());
		case 1:
			return DpUtils.trim(rs.getDivision());
		case 2:
			return DpUtils.trim(rs.getJournal());
		case 3:
			return String.valueOf(rs.getNumber());
		case 4:
			return DpUtils.trim(rs.getType());
		case 5:
			return DpUtils.trim(rs.getSubType());
		case 6:
			return DpUtils.trim(rs.getLedger());
		case 7:
			return DpUtils.trim(rs.getDescription());
		case 8:
			return DpUtils.trim(rs.getCustomer());
		case 9:
			return DpUtils.trim(rs.getResource());
		case 10:
			return DpUtils.trim(rs.getYourReference());
		case 11:
			return DpUtils.trim(rs.getCurrency());
		case 12:
			value = rs.getExchangeRate();
			return value != 0 ? DpUtils.format(value, format) : "";
		case 13:
			value = rs.getDebitFC();
			return value != 0 ? DpUtils.format(value, format) : "";
		case 14:
			value = rs.getCreditFC();
			return value != 0 ? DpUtils.format(value, format) : "";
		case 15:
			value = rs.getDebitVND();
			return value != 0 ? DpUtils.format(value, formatVND) : "";
		case 16:
			value = rs.getCreditVND();
			return value != 0 ? DpUtils.format(value, formatVND) : "";
		case 17:
			return DpUtils.trim(rs.getProjectCode());
		case 18:
			return DpUtils.trim(rs.getCostCenter());
		default:
			break;
		}
		return "=";
	}

	public void addListener(ILabelProviderListener listener) {
	}

	public void dispose() {
	}

	public boolean isLabelProperty(Object element, String property) {
		return false;
	}

	public void removeListener(ILabelProviderListener listener) {
	}

	@SuppressWarnings("unchecked")
	public Color getBackground(Object element) {
		if (null != list && !list.isEmpty()) {
			int row = list.indexOf(element);
			if (row % 2 == 0) {
				return odd;
			}
			return event;
		}
		return null;
	}

	public Color getForeground(Object element) {
		return null;
	}

}
